package cn.kgc.viny.smbms.service.impl;

import cn.kgc.viny.smbms.entity.User;
import cn.kgc.viny.smbms.mapper.RoleMapper;
import cn.kgc.viny.smbms.mapper.UserMapper;
import cn.kgc.viny.smbms.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;
    @Resource
    private RoleMapper roleMapper;
    @Override
    public User findUser(String userCode, String userPassword) {
        return this.userMapper.selectUser(userCode,userPassword);
    }

    @Override
    public PageInfo<User> find(User condition, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<User> userList=this.userMapper.select(condition);
        PageInfo<User> pageInfo=new PageInfo<>(userList);
        return pageInfo;
    }

    @Override
    public void add(User user) {
        this.userMapper.insert(user);
    }

    @Override
    public Integer findUserCount(String userCode) {
        return this.userMapper.selectUserCount(userCode);
    }

    @Override
    public User findById(Long userId) {
        return this.userMapper.selectById(userId);
    }

    @Override
    public void modify(User user) {
        this.userMapper.update(user);
    }

    @Override
    public List<User> findUsersByRoleId(Long roleId) {
        return this.userMapper.selectUsersByRoleId(roleId);
    }
}
